package com.example.siyun.controller.ordercontroller;

import com.example.siyun.pojo.SyUserOrder;
import com.example.siyun.service.orderservice.OrderService;
import com.example.siyun.util.JsonResult;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 课程订单列表
 *@author：王浩宇
 *@Date: 2022-10-12
 * */
@RestController
@RequestMapping("/primary")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderServer;


    /**
    * 获取全部课程订单
    * @page:页数
     * @limit:条数
     * @return: 课程订单数据
    * */
    @RequestMapping("/get")
    public  PageResult<List> get(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.Get();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 课程订单搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return: 课程订单数据
     * */
    @RequestMapping("/select")
    public  PageResult<List> select(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        Map<String, Object> map = new HashMap<>();

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.Select(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     * 课程待付款订单数据
     * @page:页数
     * @limit:条数
     * @return: 课程待付款订单数据
     * */
    @RequestMapping("/getPayment")
    public  PageResult<List> getPayment(Integer page, Integer limit){
        Map<String, Object> map = new HashMap<>();

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.getPayment();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 课程待付款订单搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return: 课程待付款订单数据
     * */
    @RequestMapping("/selectPayment")
    public  PageResult<List> selectPayment(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.selectPayment(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 课程已完成订单数据
     * @page:页数
     * @limit:条数
     * @return: 课程已完成订单数据
     * */
    @RequestMapping("/getPaid")
    public  PageResult<List> getPaid(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.getPaid();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 课程已完成订单搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return: 课程已完成订单数据
     * */
    @RequestMapping("/selectPaid")
    public  PageResult<List> selectPaid(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.selectPaid(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     * 课程已取消订单数据
     * @page:页数
     * @limit:条数
     * @return: 课程已取消订单数据
     * */
    @RequestMapping("/getCancel")
    public  PageResult<List> getCancel(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.getCancel();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 课程已取消订单搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return: 课程已取消订单数据
     * */
    @RequestMapping("/selectCancel")
    public  PageResult<List> selectCancel(String orderSource, String orderStatus, String orderPaymentChannel, Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = orderServer.selectCancel(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);


        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     *课程订单总数
     * @return:课程订单总数
     * */
    @RequestMapping("/number")
    public JsonResult<Integer> number(){
        int a = orderServer.Number();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *课程待付款订单总数
     * @return:课程待付款订单总数
     * */
    @RequestMapping("/numberPayment")
    public JsonResult<Integer> numberPayment(){
        int a = orderServer.numberPayment();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *课程已完成订单总数
     * @return:课程已完成订单总数
     * */
    @RequestMapping("/numberPaid")
    public JsonResult<Integer> numberPaid(){
        int a = orderServer.numberPaid();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *课程已取消订单总数
     * @return:课程已取消订单总数
     * */
    @RequestMapping("/numberCancel")
    public JsonResult<Integer> numberCancel(){
        int a = orderServer.numberCancel();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }

}
